package se.study.jdbc;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

import javax.sql.DataSource;
import javax.sql.PooledConnection;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @Author: tiger
 * @Date:2018/5/23
 * @Description: 连接池测试
 */
public class ConPoolTest {
    public static void main(String[] args) throws SQLException {
        Connection con = JDBCUtil.getConnection();
        try {
            String delSql = "DELETE FROM `user` WHERE id = ?";

            // 设置事务不自动提交
            con.setAutoCommit(false);
            JDBCUtil.startTransaction();
            // 3.获取PreparedStatement对象
            PreparedStatement preState = con.prepareStatement(delSql);
            preState.setInt(1, 1);
            // 4.执行SQL
            int execute = preState.executeUpdate();
            // 事务提交
            JDBCUtil.commit();
            // 5.处理ResultSet结果集
            System.out.println("执行结果：" + execute);
            // 6.关闭资源
            preState.close();
            con.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

        JDBCUtil.close();
    }


}
